package com.ruoyi.project.app.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.app.service.AppLoginService;
import com.ruoyi.project.app.util.XResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 用户登录模块
 */
@RestController
@RequestMapping("/app/login")
@Api(tags = "登录模块")
public class AppLoginController {

    @Autowired
    private AppLoginService appLoginService;


    /**
     * 用户登录接口
     * @param params
     * @return
     */
    @PostMapping
    @ApiOperation(notes = "login", value = "用户登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "电话号码", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "uuid", value = "imei", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "code", value = "验证码", required = true, paramType = "query", dataType = "string"),
    })
    public Object login(@RequestParam @ApiIgnore Map<String, String> params,@ApiIgnore HttpServletRequest request) {
        return new XResult("登录成功",appLoginService.login(params.get("phone"),params.get("uuid"),params.get("code"),request));
    }




    /**
     * 发送验证码接口
     * @param params
     * @return
     */
    @PostMapping("sendCode")
    @ApiOperation(notes = "sendCode", value = "发送验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "电话号码", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "发送验证码类型(1:登录验证2:实名认证)", required = true, paramType = "query", dataType = "string")
    })
    public Object sendCode(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request)  {
        return new XResult("发送成功", appLoginService.sendCode(
                params.get("phone"),
                request,
                params.get("type")
        ));
    }



    /**
     * 验证验证码是否正确
     * @param params
     * @param request
     * @return
     */
    @PostMapping("verify")
    @ApiOperation(notes = "verify", value = "验证验证码是否正确")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "电话号码", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "code", value = "验证码", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "type", value = "验证码类型(1:登录验证2:实名认证)", required = true, paramType = "query", dataType = "string")
    })
    public Object verify(@RequestParam @ApiIgnore Map<String, String> params, @ApiIgnore HttpServletRequest request)  {
        return new XResult("发送成功", appLoginService.verify(
                params.get("code"),
                request,
                params.get("phone"),
                params.get("type")
        ));
    }
}
